//
//  ProgressShade.m
//  MBProgressHUD的使用和封装
//
//  Created by 廖易诚 on 16/9/8.
//  Copyright © 2016年 liaoyicheng. All rights reserved.
//

#import "ProgressShade.h"
#import "MBProgressHUD.h"


@interface ProgressShade ()


@end

@implementation ProgressShade

+ (instancetype)shade {
    static ProgressShade *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[ProgressShade alloc] init];
    });
    return instance;
}

/// 影藏
- (void)hiddenShade {
    [self.hud hideAnimated:YES];
}

/// 普通菊花旋转样式
- (void)showAddtoView:(UIView *)superView {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:superView animated:YES];
    self.hud = hud;
}

/// 菊花附带文字样式
- (void)showMessage:(NSString *)message addToView:(UIView *)superView {
    [self showAddtoView:superView];
    self.hud.label.text = message;
}

/// 菊花附带详细文字样式
- (void)showMessage:(NSString *)message detailMessage:(NSString *)detailMessage addToView:(UIView *)superView {
    [self showMessage:message addToView:superView];
    self.hud.detailsLabel.text = detailMessage;
}

/// 自定义的View
- (void)showCustomView:(UIView *)customView addToView:(UIView *)superView {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:superView animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = customView;
    hud.square = YES;
    [hud hideAnimated:YES afterDelay:3.f];
    
}

/// 纯文本
- (void)showOnlyMessage:(NSString *)message addToView:(UIView *)superView {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:superView animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    [hud hideAnimated:YES afterDelay:3.f];
}

/// 显示圆圈进度
- (void)showProgress:(CGFloat)progress addToView:(UIView *)superView {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:superView animated:YES];
    // MBProgressHUDModeDeterminate // 粗边框圆圈
    // MBProgressHUDModeIndeterminate // 菊花
    // MBProgressHUDModeDeterminateHorizontalBar // 进度条
    // MBProgressHUDModeAnnularDeterminate // 细边圆圈
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.progress = progress;
    hud.label.text = @"loading";
    self.hud = hud;
}

- (void)setDimBackground:(BOOL)dimBackground {
    _dimBackground = dimBackground;
    if (dimBackground) {
        self.hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
        self.hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.1f];
    }
}





@end
